package com.ysjy.course.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

@Data
@ApiModel("机构课程表")
public class OrgCourse extends Course {
    @ApiModelProperty("是否已开班")
    private Boolean useClass;
    @ApiModelProperty(value = "班级关联ID")
    private Long classId;
    @ApiModelProperty("课程分类")
    private String tagName;
    @ApiModelProperty("场地名称")
    private String siteName;

    @ApiModelProperty("上架机构（学校）id列表（多个,逗号隔开）")
    private String orgIds;
    @ApiModelProperty("上架机构（学校）名称列表")
    private String orgNames;
    @ApiModelProperty("采集的课程标识")
    private String courseUniqueId;
    @ApiModelProperty("学年")
    private String schoolYear;
    @ApiModelProperty("学期")
    private String semester;
    @ApiModelProperty("授课老师")
    private Long teacherId;
    @ApiModelProperty("授课老师")
    private String teacherName;
    @ApiModelProperty("场地ID")
    private Long siteId;
    @ApiModelProperty("最大报名人数")
    private Integer maxSignUpNum;
    @ApiModelProperty("上课时间 多个','分隔")
    private String classTime;
    @ApiModelProperty("开课 起始时间")
    private Date startTime;
    @ApiModelProperty("开课 截至时间")
    private Date endTime;
    @ApiModelProperty("报名开始时间")
    private Date signUpStartTime;
    @ApiModelProperty("报名结束时间")
    private Date signUpEndTime;

    @ApiModelProperty("已报名数")
    private int signUpNum;
    @ApiModelProperty("报名状态 0未开始、1报名中、2已结束、3已报名、4已报满")
    private Integer signUpStatus;
    @ApiModelProperty("上架状态：0未上架 1上架")
    private Integer shelvesStatus;
    @ApiModelProperty("上架时间")
    private Date shelvesTime;

    public void initSignUpStatus() {
        if (signUpStatus != null || signUpStartTime == null || signUpEndTime == null) return;
        if (maxSignUpNum != null && maxSignUpNum <= signUpNum) {
            signUpStatus = 4;
            return;
        }
        Date currDate = new Date();
        if (currDate.getTime() > signUpEndTime.getTime()) {
            signUpStatus = 2;
            return;
        }
        if (currDate.getTime() > signUpStartTime.getTime()) {
            signUpStatus = 1;
            return;
        }
        signUpStatus = 0;
    }
}
